package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.RefundManagementItem;
import cn.wolfcode.crm.mapper.RefundManagementItemMapper;
import cn.wolfcode.crm.query.RefundManagementItemQueryObj;
import cn.wolfcode.crm.service.IRefundManagementItemService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RefundManagementItemServiceImpl implements IRefundManagementItemService {

    @Autowired
    private RefundManagementItemMapper refundManagementItemMapper;

    public void delete(Long id) {
        refundManagementItemMapper.deleteByPrimaryKey(id);
    }

    public void save(RefundManagementItem entity) {
        if(entity != null){
            //设置状态
            entity.setAuditState(0);
            refundManagementItemMapper.insert(entity);
        }
    }

    public void update(RefundManagementItem entity) {
        refundManagementItemMapper.updateByPrimaryKey(entity);
    }

    public RefundManagementItem get(Long id) {
        return refundManagementItemMapper.selectByPrimaryKey(id);
    }

    public List<RefundManagementItem> list() {
        return refundManagementItemMapper.selectAll();
    }

    public PageResult query(RefundManagementItemQueryObj qo) {

        //查总数
        int total = refundManagementItemMapper.queryForCount(qo);
        if(total == 0){
            return new PageResult();
        }
        //查数据
        List<RefundManagementItem> rows = refundManagementItemMapper.queryForList(qo);
        return new PageResult(total, rows);
    }
    //审核
    public void audit(Long id) {

        refundManagementItemMapper.audit(id);
    }
}
